/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package interfaceJogo;

import java.util.ArrayList;

/**
 *
 * @author Administrador
 */
public class EscalaDefesa extends javax.swing.JFrame {

    Menu1 m1;
    ArrayList r;
     public EscalaDefesa(Menu1 m, boolean f, ArrayList r) {
         
        this.m1=m;
        this.r =r ;
        if (f) {
               
        this.r = new ArrayList();

             geraR();
         }
        initComponents();
        setVisible(true);
    }

    public ArrayList removeR(String nome){
             for (int i = 0; i < r.size(); i++) {
             r.remove(nome);
           }
    
     return r;
    }
    public void geraR(){
        for (int i = 0; i < m1.voce.getTime().getElenco().size(); i++) {
            if (m1.voce.getTime().getElenco().get(i).getPosicao().equalsIgnoreCase("zagueiro")||m1.voce.getTime().getElenco().get(i).getPosicao().equalsIgnoreCase("lateral")) {
                r.add(m1.voce.getTime().getElenco().get(i).getNome());
            }
    }
    }
   
       

    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        comboAta = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(0, 153, 102));
        jPanel1.setForeground(new java.awt.Color(0, 153, 51));

        for (int i = 0; i < r.size(); i++) {
            comboAta.addItem(r.get(i));
        }

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Escolha um Defensor");

        jButton1.setText("Próximo");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(97, 97, 97)
                        .addComponent(comboAta, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(109, 109, 109)
                        .addComponent(jLabel1))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(146, 146, 146)
                        .addComponent(jButton1)))
                .addContainerGap(133, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(49, 49, 49)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(comboAta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(50, 50, 50)
                .addComponent(jButton1)
                .addContainerGap(123, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        for (int i = 0; i < m1.voce.getTime().getElenco().size(); i++) {
            if (comboAta.getSelectedItem().toString().equalsIgnoreCase(m1.voce.getTime().getElenco().get(i).getNome())) {
              
        m1.voce.getTime().escalaJogador(m1.voce.getTime().getDef(),i , m1.defesa);
        m1.defesa++;
            }
    
                }
        this.setVisible(false);
        if (m1.voce.getTime().getDef().length>m1.defesa) {
            new EscalaDefesa(m1,false, removeR(comboAta.getSelectedItem().toString()));
        }else
            new EscalaMeio(m1, true,null);
        
    }

    /**
     * @param args the command line arguments
     */
    
    // Variables declaration - do not modify
    private javax.swing.JComboBox comboAta;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration
}
